#!/bin/bash

TRAIN_NUMBER=$1
LAST_SPEED=""
LAST_SENSOR=""
LAST_TIME=""
while read line; do
  CURR_SPEED=$(echo $line | cut -d" " -f2)
  CURR_SENSOR=$(echo $line | cut -d" " -f3)
  CURR_TIME=$(echo $line | cut -d" " -f4)
  if [[ CURR_SPEED -eq LAST_SPEED ]]; then
    DIFF_TIME=$((CURR_TIME-LAST_TIME))
    DIST=$(python path.py $LAST_SENSOR $CURR_SENSOR < trackb)
    echo "$TRAIN_NUMBER $CURR_SPEED $LAST_SENSOR $CURR_SENSOR $DIST $DIFF_TIME"
  fi
  LAST_SPEED=$CURR_SPEED
  LAST_SENSOR=$CURR_SENSOR
  LAST_TIME=$CURR_TIME
done < timing-$1.txt
